﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers {
    import flash.events.*;
    import net.wooga.pets.loading.vos.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.vo.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.fountain.*;

    public class CollectAchievementRewardCommand extends Command {

        public var event:InfoEvent;
        public var symbolModel:SymbolModel;
        public var userModel:UserModel;
        public var energyModel:EnergyModel;

        override public function execute():void{
            var _local1:RewardVO = (this.event.info as RewardVO);
            var _local2:Object = {taskType:GameConstants.GET_ACHIEVEMENT, itemType:_local1.id, onResult:this.onResult};
            var _local3:RequestVO = new RequestVO("collect_achievement", {id:this.event.id});
            var _local4:Array = [_local3];
            var _local5:TaskRequestEvent = new TaskRequestEvent(EventConstants.SEND_TASK_REQUEST, _local4, _local2);
            dispatch(_local5);
        }
        private function onResult(_arg1:ResultVO):void{
            var _local2:Object;
            var _local3:Object;
            if (_arg1.success){
                _local2 = _arg1.data.collect_achievement;
                dispatch(new Event(EventConstants.ACHIEVEMENT_REWARD_COLLECTED));
                this.userModel.xpPoints = _local2.xp;
                this.userModel.coins = _local2.coins;
                dispatch(new UserModelEvent(UserModelEvent.ON_MODEL_CHANGED));
                this.symbolModel.symbols = _local2.symbols;
                _local3 = _local2.energy;
                this.energyModel.energyStartedAt = _local3.started_at;
                this.energyModel.energyUsed = _local3.used;
                this.energyModel.energyMax = _local3.max_value;
                this.energyModel.energyRefillDuration = _local3.refill_duration;
                this.energyModel.energyExtra = _local3.extra;
            };
        }

    }
}//package net.wooga.pets.controllers 
